﻿Imports BusinessLogic
Imports System.Net.Mail
Imports System.Xml
Partial Class AdvertiseWus
    Inherits System.Web.UI.Page

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim _Advertise As New Advertise()
        _Advertise.CompanyName = txtCompanyName.Text.Trim()
        _Advertise.ContactName = txtContactName.Text.Trim()
        _Advertise.Description = txtDescription.Text.Trim()
        _Advertise.Save()

        Try

            ' create the email message 
            Dim _MailBody As String
            Dim oXmlDocument As New XmlDocument()
            oXmlDocument.Load(Server.MapPath("~/XML/AdvertiseMailBody.xml"))
            _MailBody = String.Format(oXmlDocument.InnerXml, _Advertise.CompanyName, _Advertise.ContactName, _Advertise.Description)

            Dim message As New MailMessage()
            message.Body = _MailBody
            message.Subject = String.Format("New Advertisement Request")
            message.To.Add(ConfigurationManager.AppSettings("ToAdMail"))
            ' create and add the attachment(s)
            'Dim attachment As New Attachment("sample.doc", MediaTypeNames.Application.Octet)
            'message.Attachments.Add(attachment)
            ' create SMTP Client and add credentials 
            Dim smtpClient As New SmtpClient()
            smtpClient.UseDefaultCredentials = True
            ' Email with Authentication 
            'smtpClient.Credentials = New Net.NetworkCredential("userID", "password", "domainName")
            'Send the message 
            smtpClient.Send(message)
        Catch ex As Exception
            ClientScript.RegisterHiddenField("error", ex.Message)
        End Try
    End Sub
End Class
